import http from "@/service/request";
import type { params } from "../type";

enum API {
  // 添加购物车
  SET_CART = "/api/shop/shoppingCart",
  // 获取购物车信息
  GET_CART = "/api/shop/shoppingCart",
  //根据id删除购物车商品
  DELETE_CART_ITEM = "/api/shop/shoppingCart/",
  //更新购物车信息
  UPDATE_CART_ITEM = "/api/shop/shoppingCart/",
}

export function api_set_cart(data: data) {
  return http({
    method: "POST",
    url: API.SET_CART,
    data,
  });
}

export function api_get_cart() {
  return http({
    method: "GET",
    url: API.GET_CART,
  });
}

export function api_delete_cart_item(id: number) {
  return http({
    method: "DELETE",
    url: API.DELETE_CART_ITEM + id,
  });
}

export function api_update_cart_item(id: number, data: data) {
  return http({
    method: "PUT",
    url: API.UPDATE_CART_ITEM + id,
    data,
  });
}

interface data {
  goods_id?: number;
  num: number;
}
